package com_.dxy_test_.safe_fail_;

import java.util.concurrent.ConcurrentHashMap;

/**
 * @Description 安全失败测试
 * @Author dangxianyue
 * @Date 2022/10/12 10:14
 */
public class SafeFailTest {

    public static void main(String[] args) {
        ConcurrentHashMap<String, Object> map = new ConcurrentHashMap<>();
        map.put("a","1");
        map.put("b","2");
        map.put("c","3");
        map.put("d","4");

//        for (String key : map.keySet()) {
//            if ("b".equals(key)) {
//                map.remove(key);
//            }
//        }

        map.forEach((k,v) -> {
            if ("b".equals(k) || "d".equals(k)) {
//                map.remove(k);
                return;
            }
            System.out.println("K: " + k + ", v: " + v);
        });

        System.out.println(map);
    }
}
